package edu.gdkm.sql.dao;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import edu.gdkm.sql.pojo.ProductDetail;
import org.springframework.stereotype.Repository;

import java.util.List;
@Repository
public interface ProductDetailMapper {

    // Create
    @Insert("INSERT INTO productdetail (goodspicurl, goodsdes, stock, brand, productid) VALUES (#{goodspicurl}, #{goodsdes}, #{stock}, #{brand}, #{productid})")
    // Update
    @Update("UPDATE productdetail SET goodspicurl = #{goodspicurl}, goodsdes = #{goodsdes}, stock = #{stock}, brand = #{brand} WHERE id = #{id}")
    int updateProductDetail(ProductDetail productDetail);

    // Read
    @Select("SELECT * FROM productdetail WHERE id = #{id}")
    ProductDetail getProductDetailById(int id);
    @Select("SELECT * FROM productdetail WHERE productid = #{productid}")
    ProductDetail getProductDetailByProductId(int productid);

    @Select("SELECT * FROM productdetail")
    List<ProductDetail> getAllProductDetails();

    // Delete
    @Delete("DELETE FROM productdetail WHERE id = #{id}")
    int deleteProductDetail(int id);
}